I'm trying to read from the clipboard on my Chrome extension. I'm using the navigator.clipboard.readText() method from the ClipboardAPI to do so (because document.execCommand('paste') is deprecated). However, not only does the method fail to ask for user permission to read from clipboard (as done on regular web apps), but all it returns is a "pending" promise that does not get fulfilled nor rejected.
Here's the code block I'm running on a function. Neither the clipboardString variable nor err variable gets logged on the console. And the method itself returns a promise that remains "pending" forever.
navigator.clipboard
.readText()
.then((clipboardString) => {
console.log('Clipboard Contains: ', clipboardString);
})
.catch((err) => {
console.log('Clipboard Error: ', err);
});
Any solutions to this problem? Either what's happening with this pending promise or how to read from clipboard on a Chrome extension? Thank you.